<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <script src="js/time.js?"></script>
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
        
        <script>
        function addp()
        {
            //得到当前数组的长度
        	var i = document.getElementsByName("childP").length;
        	//alert(i);
        	
            //策略号为当前最大的编号 加1
            var obj = document.getElementById("strategyid"+(i-1));
            var showValue= 0;
            if(null != obj)
            {
                showValue = obj.value;
            }
            showValue = parseInt(showValue) + 1;
			//alert(showValue);
            var strOption='';
            var modList = <?=json_encode($moduleList)?>;
			//alert(modList);
            for(var one in modList)
            {
            	strOption += '<option value="'+modList[one]['tableenum']+'" >'+modList[one]['des']+'</option>';
            }
            //alert(strOption);
            str = '<center><table id ="p'+i+'" name="childP" border="0" width="300">'+
		  		      '<tr>'+
			        '<td>&nbsp;</td>'+
			        '<td>&nbsp;</td>'+
			      '</tr>'+
			      '<tr>'+
			        '<td>&nbsp;<?= translate('ACTIVITY_GROUPSTATEGY_MODULENAME') ?>'+
			          '</td>'+
			        '<td>'+
						'<select  name="row[module]['+i+'][tableenum]" id="tableenum'+i+'" onChange="getStrategyId('+i+')">'+
						'<option value=""><?= translate('PLASE_SELECT') ?></option>'+
						strOption+
           	      		'</select>'+
			        '</td>'+
			      '</tr>'+
			      '<tr>'+
			        '<td>&nbsp;<?= translate('ACTIVITY_STRATEGY_STRAGEGYNAME') ?>'+
			          '</td>'+
			        '<td>'+
				        '<select  name="row[module]['+i+'][strategyid]" id="strategyid'+i+'">'+
						'<option value="">&nbsp;<?= translate('PLASE_SELECT') ?></opton>'+
	   	      			'</select>'+
			        '</td>'+
			      '</tr>'+
			      '<tr>'+
			        '<td>&nbsp;<?= translate('ACTIVITY_MODULE_DES') ?>'+
			          '</td>'+
			        '<td >'+
			            '<input type="text"  name="row[module]['+i+'][des]" id="des'+i+'"/>'+
			        '</td>'+
			    '</table></center>';
            //alert(str);	
            $("#add").append(str);
            autocomplete();
            $("#des"+i).formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
            //$("#strategyid"+i).formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'});
        	//$("#des"+i).formValidator({empty: false, onshow: '<?= translate('C_ONLY_NUM') ?>'}).regexValidator({regexp: "^(0\.\d*[1-9])|(1)$", onerror: '<?= translate('C_NUM_BETTWEEN_0_AND_1') ?>'}); 
   		}
        function removep()
        {
        	var i = document.getElementsByName("childP").length-1;
            //alert(i);
            if (i > 0)
            {
                //alert(i);
                $("#p" + i).remove();
                //i--;
            }
        }
    	
    	function getStrategyId(i)
    	{

        	var tableenum = $('#tableenum'+i).val();
        	//alert(tableenum);

        	//判断选的模块名是否合法 之前是否已经选择过了？
        	
        	
        	var msl = <?=json_encode($modStrategyList)?>;
        	var strOption = '';
        	for(var one in msl[tableenum])
            {
            	strOption += '<option value="'+one+'" >'+msl[tableenum][one]+'</option>';
            }
        	//alert(strOption); 
			$('#strategyid'+i).html(strOption);
    	} 

    	function checkValid()
    	{
        	return true;
    		var beginTime = $("#starttime").val();
    	    var endTime = $("#endtime").val();
    	    var beginTimes = beginTime.substring(0, 10).split('-');
    	    var endTimes = endTime.substring(0, 10).split('-');

    	    beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
    	    endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);

    	    alert(beginTime + "aaa" + endTime);
    	    alert(Date.parse(endTime));
    	    alert(Date.parse(beginTime));
    	    var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
    	    if (a <= 0) {
    	        alert("endTime must be big then startTime");
    	        return false;
    	    }        	
        	return true;
    	}

    	function getModuleList()
    	{
    		var modList = <?=json_encode($moduleList)?>;
			//alert(modList);
			var strOption = '';
            for(var one in modList)
            {
            	strOption += '<option value="'+modList[one]['tableenum']+'" >'+modList[one]['des']+'</option>';
            }
            return strOption;
    	}
    	
        </script>
        
    </head>
    <body>
    	<?php include(VIEWPATH . 'common/main_header.php'); ?>
    	
    	<?php
    		//print_r($moduleList);
    		//print_r($modStrategyList); 
    	?>
    	
    	 <?php
    	 	 $strOP = "";
              foreach ($moduleList as $key => $value)
              {
              	//echo " key = $key  value = ".$value['des'];
              	//print_r($value);
              	//$strOP .= "<option value='$key' >{$value[des]}</option>";
              	$strOP .= "".$key.$value['des'];
              }
           //echo " strop = $strOP ";
         ?>
    	
        <form action="" method="POST" id="rowForm">
            <table id="add" width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
            
	            <tr>
			      <td><?= translate('SELECT_AREA') ?>:</td>
			      <td><?= $arealist ?></td>		        
			    </tr>
			    
                <tr><td><?= translate('ACTIVITY_GROUP_NAME') ?>:</td>
                <td><input type="text" name="row[activityname]" id="activityname" size="25" /></td></tr>
                <tr><td><?= translate('STARTTIME') ?>:</td><td>
                	<input type="text" name="row[starttime]" id="starttime" size="25" onClick="SelectDate(this,'yyyy-MM-dd hh:mm:ss',0,10)"/>
                </td></tr>
                <tr><td><?= translate('ENDTIME') ?>:</td><td>
                	<input type="text" name="row[endtime]" id="endtime" size="25" onClick="SelectDate(this,'yyyy-MM-dd hh:mm:ss',0,10)"/>
                </td></tr>
                <!-- 
                <tr><td><?= translate('ACTIVITY_GROUPAREA_AREAID') ?>:</td><td>
               	  <?= translate('ACTIVITY_GROUP_SELECTALL') ?>:<input type="checkbox" name="allselect" id="allselect">
               	  </td></tr>
                <tr><td>&nbsp;</td><td>
                	<?php foreach ($areaList as $key => $value) { ?>
                        <label for="area"><?=$key.":".$value ?></label>
                        <input type="checkbox" name="area" id="area<?=$key ?>" value="<?=$key ?>">&nbsp;&nbsp;&nbsp;&nbsp;                	
                	<?php }?>
              </td></tr>
               -->
               
		      
              <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
              </table>
 
             
               
              <table id="add" name="childP" border="0" width="300">
		  		      <tr>
			        <td>&nbsp;</td>
			        <td>&nbsp;</td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_GROUPSTATEGY_MODULENAME') ?>
			          </td>
			        <td>
						<select  name="row[module][0][tableenum]" id="tableenum0" onChange="getStrategyId(0)">
							<option value=""><?= translate('PLASE_SELECT') ?></option>
							<script type="text/javascript">
								document.write(getModuleList());
							</script>
           	      		</select>
			        </td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_STRATEGY_STRAGEGYNAME') ?>
			          </td>
			        <td>
				        <select  name="row[module][0][strategyid]" id="strategyid0">
						<option value="">&nbsp;<?= translate('PLASE_SELECT') ?></opton>
	   	      			</select>
			        </td>
			      </tr>
			      <tr>
			        <td>&nbsp;<?= translate('ACTIVITY_MODULE_DES') ?>
			          </td>
			        <td >
			            <input type="text"  name="row[module][0][des]" id="des0"/>
			        </td>
			    </table>
			  
              <table width="100%">
		      <tr>
		        <td><div align="center">
		            <input type="button" onClick="addp()" value="<?= translate('ADD_ONE') ?>" />
		          </div></td>
		        <td><div align="center">
		            <input type="button" onClick="removep()" value="<?= translate('REMOVE_ONE') ?>" />
		          </div></td>
		      </tr>
                <tr><td></td>
                <td><input type="submit" value="<?= translate('SUBMIT') ?>" id="submit" onClick="return checkValid()"/> 
                <input type="reset" value="<?= translate('RESET') ?>" id="reset"/>
                </td></tr>
            </table>
            
        </form>
        <script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                //$("#groupname").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#activityname").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#starttime").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).regexValidator({regexp: "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$", onerror: '<?= translate('C_INVALID_TIME') ?>'});
                $("#endtime").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).regexValidator({regexp: "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$", onerror: '<?= translate('C_INVALID_TIME') ?>'});
                $("#des0").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                //$("#endtime").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                });
        </script>
    </body>
</html>
